//
//  UserSecurityController.m
//  CheekiOS
//
//  Created by mac on 2017/6/22.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "UserSecurityController.h"

@interface UserSecurityController ()

@property (nonatomic, strong)UISwitch *switchBtn;

@end

@implementation UserSecurityController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavgationBarHiddenNo];
    self.title = @"设备与安全";
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, KScreenWidth, 55)];
    backView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:backView];
    
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 25, 25)];
    imgView.image = [UIImage imageNamed:@"p_center_szaq_lock_button"];
    [backView addSubview:imgView];
    
    UILabel *accountLab = [[UILabel alloc] initWithFrame:CGRectMake(imgView.right+10, 15, 100, 25)];
    accountLab.font = FontP(15);
    accountLab.text  = @"账号保护";
    accountLab.textAlignment = NSTextAlignmentLeft;
    accountLab.textColor = [UIColor blackColor];
    [backView addSubview:accountLab];
    
    _switchBtn = [[UISwitch alloc] init];
    [backView addSubview:_switchBtn];
    [_switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backView).offset(-45);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(25);
        make.top.equalTo(backView).offset(12.5);
    }];
    if ([_deviceProtect isEqualToString:@"0"]) {
        _switchBtn.on = NO;//设置初始为ON的一边

    }else{
        _switchBtn.on = YES;//设置初始为YES的一边

    }
    _switchBtn.onTintColor= Colorbackground;
    [_switchBtn addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];

    UILabel *Tlab = [[UILabel alloc] initWithFrame:CGRectMake(15, backView.bottom+10, KScreenWidth, 20)];
    Tlab.text = @"开启账号保护后，贴脸儿账号只能在一台设备上使用！";
    Tlab.textColor = ColorI(0x2e353f);
    Tlab.font = FontP(12);
    Tlab.textAlignment = NSTextAlignmentLeft;
    
    [self.view addSubview:Tlab];

}


-(void)switchAction:(id)sender
{
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn) {
        NSDictionary *dict = [NSDictionary dictionary];
        dict =@{@"deviceProtect":@"1",
                @"uid":[HQHttpManager getUserId]
                };
        [HcardHttpmanager MakePersionalInfoWithParam:dict success:^(id sucess) {
            if(sucess){
                NSLog(@"设置成功");
                NSString *Str = @"UserSecurityControllerNotification";
                [[NSNotificationCenter defaultCenter] postNotificationName:Str object:nil
                 ];
                

            }
        } failure:^(NSError *error) {
            
        }];
    
    }else {
        NSDictionary *dict = [NSDictionary dictionary];
        dict =@{@"deviceProtect":@"0",
                @"uid":[HQHttpManager getUserId]
                };
        [HcardHttpmanager MakePersionalInfoWithParam:dict success:^(id sucess) {
            if(sucess){
                NSLog(@"设置成功");
                NSString *Str = @"UserSecurityControllerNotification";
                [[NSNotificationCenter defaultCenter] postNotificationName:Str object:nil
                 ];
                

                
            }
        } failure:^(NSError *error) {
            
        }];
    }
}



@end
